//
// Created by cube on 2020/10/22.
//

#include "Library.h"
using namespace LibraryCommon;

#if __linux

void* Base::open(const char *path,int model) {return dlopen(path,model);}
void* Base::get(void *pid_p,const char *identifier) {return dlsym(pid_p,identifier);}
int Base::close(void *pid_p) {return dlclose(pid_p);}
char* Base::error() {return dlerror();}

//Library

Library::Library():__pid(nullptr) {}
Library::Library(const std::string &path):__pid(nullptr) {
    open(path);
}

void Library::open(const std::string &path) {
    __pid = Base::open(path.data(),0);
}

void* Library::get(const std::string& identifier) {
    if(__pid == nullptr)return nullptr;
    return Base::get(__pid,identifier.data());
}

void Library::close() {
    if(__pid != nullptr)Base::close(__pid);
}

#endif

#if WIN32

void* Base::open(const char *path,int model) {
    return nullptr;
}

void* Base::get(void* pid_p,const char* identifier) {
    return nullptr;
}

int Base::close(void *hmodule) {
return 0;
}

char* Base::error() {
return nullptr;
}

//Library

Library::Library(const std::string &path) {

}

void Library::open(const std::string &path) {

}

void* Library::get(const std::string &identifier) {
return nullptr;
}

void Library::close() {

}

#endif